package com.neuedu.jdboot.converter;

import java.util.ArrayList;
import java.util.List;

import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

import com.neuedu.jdboot.bean.Privilege;
import com.neuedu.jdboot.common.JdbootException;

/**
 * 
 * @author chens
 *
 */
@Component("RoleStringListConverter")
public class PrivilegeStringListConverter implements Converter<String[], List<Privilege>> {

	@Override
	public List<Privilege> convert(String[] source) {
		List<Privilege> list = new ArrayList<Privilege>();
		if (source != null && source.length > 0) {
			for (String roleId : source) {
				try {
					list.add(new Privilege(Integer.valueOf(roleId)));
				} catch (RuntimeException e) {
					throw new JdbootException("权限ID转换异常");
				}
			}
		}
		return list;
	}

}
